package com.tupi.project.ui.presenter;

import android.Manifest;
import android.util.Log;

import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.tupi.project.base.RxPresenter;
import com.tupi.project.ui.contract.PermissionContract;

import javax.inject.Inject;

import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2017/11/2.
 */

public class PermissionPresenter extends RxPresenter<PermissionContract.View> implements
        PermissionContract.Presenter
{
    private static final String TAG = PermissionPresenter.class.getSimpleName();
    
    @Inject
    public PermissionPresenter()
    {
        super();
    }
    
    @Override
    public void onClickCheckPermission(RxPermissions rxPermissions)
    {
        addSubscribe(rxPermissions.requestEach(Manifest.permission.CAMERA).subscribe(new Consumer<Permission>()
        {
            @Override
            public void accept(Permission permission) throws Exception
            {
                if (permission.granted)
                {
                    // 用户已经同意该权限
                    Log.e(TAG, permission.name + " is granted.");
                } else if (permission.shouldShowRequestPermissionRationale)
                {
                    // 用户拒绝了该权限，没有选中『不再询问』（Never ask again）,那么下次再次启动时，还会提示请求权限的对话框
                    Log.e(TAG, permission.name + " is denied. More info should be provided.");
                } else
                {
                    // 用户拒绝了该权限，并且选中『不再询问』
                    Log.e(TAG, permission.name + " is denied.");
                    mView.toSettingActivity();
                    
                    
                }
            }
        }));
    }
    
    @Override
    public void addEvent()
    {
        
    }
}
